<?php

declare(strict_types=1);

namespace App\Request\Backend;

use Hyperf\Validation\Request\FormRequest;

class MobileEditRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'id' => 'required',
            'mobile_area' => 'required',
            'mobile' => 'required',
            'mobile_area_en' => 'required',
            'card_no' => 'required',
        ];
    }

    public function validated(): array
    {
        $data = parent::validated();
        if (strpos($data['mobile_area'], '+') !== 0) {
            // 如果不是以 '+' 开头，则拼接 '+'
            $data['mobile_area'] = '+' . $data['mobile_area'];
        }
        return  $data;
    }
}
